package com.wenan.data
{
	import com.adobe.serialization.json.JSON;
	
	import mx.collections.ArrayCollection;
	import mx.utils.object_proxy;
	
	public class BrowsePageInfo
	{
		private var _pageId:String;
		private var _pageTitle:String;
		private var _pageInfo:PageInfo;
		private var _imageUrl:String;
		private var _visittimes:Number;
		private var _pageInfos:Array;
		
		public function BrowsePageInfo()
		{
		}
		
		public function get pageTitle():String
		{
			return _pageTitle;
		}

		public function set pageTitle(value:String):void
		{
			_pageTitle = value;
		}

		public function get pageId():String
		{
			return _pageId;
		}

		public function set pageId(value:String):void
		{
			_pageId = value;
		}

		public function get pageInfo():PageInfo
		{
			return _pageInfo;
		}
		
		public function set pageInfo(value:PageInfo):void
		{
			_pageInfo = value;
		}
		
		public function get imageUrl():String
		{
			return _imageUrl;
		}
		
		public function set imageUrl(value:String):void
		{
			_imageUrl = value;
		}
		
		public function get visittimes():Number
		{
			return _visittimes;
		}
		
		public function set visittimes(value:Number):void
		{
			_visittimes = value;
		}
		
		public function get pageInfos():Array
		{
			return _pageInfos;
		}
		
		public function set pageInfos(value:Array):void
		{
			_pageInfos = value;
		}
		
		public function createData(o:Object):void
		{
			_pageId = o.pageid;
			_pageTitle = o.pagetitle;
			_imageUrl = o.thumbs;
			_pageInfos = new Array();
			_visittimes = Number(o.visittimes); 
			
			var pageInfoStr:String = o.pageinfo as String;
			var resultPageInfo:Object = null;
			
			if(pageInfoStr != "" || pageInfoStr != null) 
			{
				resultPageInfo = JSON.decode(pageInfoStr);
				_pageInfo = buildPageInfo(resultPageInfo);
			}
			
			var pageInfosData:Array = resultPageInfo.pageInfos as Array;
			for(var index:int=0;index<pageInfosData.length;index++)
			{
				_pageInfos.push(buildPageInfo(pageInfosData[index]));
			}
		}
		
		private function buildPageInfo(data:Object):PageInfo
		{
			var pageInfo:PageInfo = new PageInfo();
			
			pageInfo.pageName = data.pageName;
			pageInfo.positionType = data.positionType;
			pageInfo.positionName = data.positionName;
			pageInfo.positionId = data.positionId;
			
			var parameters:Array = data.parameters as Array;
			var parameter:Parameter;
			for(var i:int=0;i<parameters.length;i++)
			{
				if (parameters[i].obj)
				{
					parameter = new Parameter(parameters[i].name, null, new ArrayCollection(parameters[i].obj as Array));
				} else 
				{
					parameter = new Parameter(parameters[i].name,parameters[i].value);
				}
				pageInfo.parameters.add(parameter);//暂未处理
			}
			
			return pageInfo;
			
		}

	}
}